import {defaultGroup} from './tools'
import { register } from '@antv/x6-vue-shape'

export const registerNode=(nodeName:string,title:string,width:number,component:any,groupName:string)=>{
  register({
    shape: nodeName,
    width,
    component: component,
  })
  defaultGroup.filter(g=>{
    return g.name===nodeName
  }).forEach(g=>{
    g.child.push({
      name:nodeName,
      title,
      props:{
        shape:nodeName,
      }
    })
  })
}

// 方式2: 遍历删除所有键
export const clearByKeys = (state:any|any[]) => {
  // 递归清空对象的所有属性
  function clearObject(obj:any|any[]) {
    if (Array.isArray(obj)) {
      // 清空数组
      obj.splice(0, obj.length);
    } else if (typeof obj === 'object' && obj !== null) {
      // 遍历对象属性并删除
      Object.keys(obj).forEach(key => {
        // 递归处理嵌套对象
        if (typeof obj[key] === 'object' && obj[key] !== null) {
          clearObject(obj[key]);
        }
        // 删除属性
        delete obj[key];
      });
    }
  }
  clearObject(state);
};
